package com.itqf.mybatis;

import com.itqf.mapper.StudentMapper;
import com.itqf.pojo.Student;
import com.itqf.utils.SqlSessionUtils;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * projectName: mybatisgp8
 *
 * @author: 赵伟风
 * time: 2021/7/29 16:42
 * description:查看properties配置是否生效
 */
public class UseMybatis {


    public static void main(String[] args) {


        InputStream resourceAsStream = null;
        try {
            resourceAsStream = Resources.getResourceAsStream("mybatis_config.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }

        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);


        SqlSession sqlSession = SqlSessionUtils.openSession();

        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);

        List<Student> students = mapper.queryOrder("s_id", "desc");
        System.out.println("students = " + students);

        sqlSession.commit();

    }


}
